<?php

namespace app\popo\dto;

use app\popo\vo\Required;
use Webman\Http\Request;

class AddressBookDTO extends BaseDto
{
    private ?int $id = null;
    
    #[Required]
    private string $consignee;
    
    #[Required]
    private string $phone;
    
    private ?string $sex = null;
    private ?string $provinceCode = null;
    private ?string $provinceName = null;
    private ?string $cityCode = null;
    private ?string $cityName = null;
    private ?string $districtCode = null;
    private ?string $districtName = null;
    
    #[Required]
    private string $detail;
    
    private ?string $label = null;
    private ?int $isDefault = null;

    public function __construct(Request $request)
    {
        $this->id = $request->input("id") ? (int)$request->input("id") : null;
        $this->consignee = $request->input("consignee", "");
        $this->phone = $request->input("phone", "");
        $this->sex = $request->input("sex");
        $this->provinceCode = $request->input("provinceCode");
        $this->provinceName = $request->input("provinceName");
        $this->cityCode = $request->input("cityCode");
        $this->cityName = $request->input("cityName");
        $this->districtCode = $request->input("districtCode");
        $this->districtName = $request->input("districtName");
        $this->detail = $request->input("detail", "");
        $this->label = $request->input("label");
        $this->isDefault = $request->input("isDefault") ? (int)$request->input("isDefault") : null;
        
        $this->validateRequired();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getConsignee(): string
    {
        return $this->consignee;
    }

    public function getPhone(): string
    {
        return $this->phone;
    }

    public function getSex(): ?string
    {
        return $this->sex;
    }

    public function getProvinceCode(): ?string
    {
        return $this->provinceCode;
    }

    public function getProvinceName(): ?string
    {
        return $this->provinceName;
    }

    public function getCityCode(): ?string
    {
        return $this->cityCode;
    }

    public function getCityName(): ?string
    {
        return $this->cityName;
    }

    public function getDistrictCode(): ?string
    {
        return $this->districtCode;
    }

    public function getDistrictName(): ?string
    {
        return $this->districtName;
    }

    public function getDetail(): string
    {
        return $this->detail;
    }

    public function getLabel(): ?string
    {
        return $this->label;
    }

    public function getIsDefault(): ?int
    {
        return $this->isDefault;
    }

    public function toArray(): array
    {
        return [
            'id' => $this->id,
            'consignee' => $this->consignee,
            'phone' => $this->phone,
            'sex' => $this->sex,
            'province_code' => $this->provinceCode,
            'province_name' => $this->provinceName,
            'city_code' => $this->cityCode,
            'city_name' => $this->cityName,
            'district_code' => $this->districtCode,
            'district_name' => $this->districtName,
            'detail' => $this->detail,
            'label' => $this->label,
            'is_default' => $this->isDefault
        ];
    }
}